choice DBE Callback

Hello,

For choice DBEs there is a Callback which fires when an item in the drop down is selected.
Is there a Callback for when 'Enter' is pressed in an editable choice DBE?

At the moment pressing 'Enter' after editing the choice DBE activates my ok DBE, causing the Dialog box to close!
SystemAdmin - Thu Sep 29 09:48:49 EDT 2011

Re: choice DBE Callback
llandale - Mon Oct 03 19:45:39 EDT 2011

Don't know your first question, but you can use this to change which DBE fires when you hit enter:

setDefault (dbe)

Set that to some other button DBE.

  • Louie

Re: choice DBE Callback
SystemAdmin - Tue Oct 04 04:53:21 EDT 2011

llandale - Mon Oct 03 19:45:39 EDT 2011
Don't know your first question, but you can use this to change which DBE fires when you hit enter:

setDefault (dbe)

Set that to some other button DBE.

  • Louie

Thanks Louie, another useful function not in the DXL Help!

I'll just add, for future reference, that setDefault(DBE) must be called after the realize(DB).

That solves half the problem.
Would still be nice to have a Callback so I can use two editable choice DBEs on one DB.
Oh well...

Re: choice DBE Callback
Peter_Albert - Tue Oct 04 05:24:15 EDT 2011

SystemAdmin - Tue Oct 04 04:53:21 EDT 2011
Thanks Louie, another useful function not in the DXL Help!

I'll just add, for future reference, that setDefault(DBE) must be called after the realize(DB).

That solves half the problem.
Would still be nice to have a Callback so I can use two editable choice DBEs on one DB.
Oh well...

First I thought that simply defining a callBack routine for the choices using

void set(DBE element, void callBack(DBE))

worked for me. It does when you type a new value and press enter. But unfortunately, when you select a value using the dropwdown list, then

string s = get(DBE element)

returns not the newly selected value, but the old value. But luckily,

int i = get(DBE element)

returns the correct value, and it even returns -1 when you have typed in a new value, hence we can differentiate all cases in the callBack:

DB     mainDB
DBE    ch1DBE, ch2DBE
string ch1[] = {"red", "green", "blue"}
string ch2[] = {"foo", "bar"}
 
void choiceCallBack(DBE dbe)
{ // General callBack routine for the choice DBE
  int    i = get dbe
  string s = get dbe
  string currVal = ""
  if (i == -1){currVal = s}
  else 
  { // User selected a value from the dropdown list
    // Unfortunately, 's' now has the wrong value, 
    // so we have to get the correct value using the
    // returned integer and the original list of choices
    if      (dbe == ch1DBE){currVal = ch1[i]}
    else if (dbe == ch2DBE){currVal = ch2[i]}
  } // User selected a value from the dropdown list
  infoBox currVal
} // General callBack routine for the choice DBE
 
mainDB = create "test"
ch1DBE = choice(mainDB, "", ch1, 0, 10, true)
ch2DBE = choice(mainDB, "", ch2, 0, 10, true)
set(ch1DBE, choiceCallBack)
set(ch2DBE, choiceCallBack)
show mainDB

 


Regards,

Peter

 

Re: choice DBE Callback
SystemAdmin - Tue Oct 04 05:51:59 EDT 2011

Peter_Albert - Tue Oct 04 05:24:15 EDT 2011

First I thought that simply defining a callBack routine for the choices using

void set(DBE element, void callBack(DBE))

worked for me. It does when you type a new value and press enter. But unfortunately, when you select a value using the dropwdown list, then

string s = get(DBE element)

returns not the newly selected value, but the old value. But luckily,

int i = get(DBE element)

returns the correct value, and it even returns -1 when you have typed in a new value, hence we can differentiate all cases in the callBack:

DB     mainDB
DBE    ch1DBE, ch2DBE
string ch1[] = {"red", "green", "blue"}
string ch2[] = {"foo", "bar"}
 
void choiceCallBack(DBE dbe)
{ // General callBack routine for the choice DBE
  int    i = get dbe
  string s = get dbe
  string currVal = ""
  if (i == -1){currVal = s}
  else 
  { // User selected a value from the dropdown list
    // Unfortunately, 's' now has the wrong value, 
    // so we have to get the correct value using the
    // returned integer and the original list of choices
    if      (dbe == ch1DBE){currVal = ch1[i]}
    else if (dbe == ch2DBE){currVal = ch2[i]}
  } // User selected a value from the dropdown list
  infoBox currVal
} // General callBack routine for the choice DBE
 
mainDB = create "test"
ch1DBE = choice(mainDB, "", ch1, 0, 10, true)
ch2DBE = choice(mainDB, "", ch2, 0, 10, true)
set(ch1DBE, choiceCallBack)
set(ch2DBE, choiceCallBack)
show mainDB

 


Regards,

Peter

 

Peter,

For me, your code closes the DB when pressing enter - without fireing the callback.

Re: choice DBE Callback
Peter_Albert - Tue Oct 04 07:32:41 EDT 2011

SystemAdmin - Tue Oct 04 05:51:59 EDT 2011
Peter,

For me, your code closes the DB when pressing enter - without fireing the callback.

Strange, which version are you running on? We are on v8.3.

Regards,

Peter

Re: choice DBE Callback
SystemAdmin - Tue Oct 04 07:40:19 EDT 2011

Peter_Albert - Tue Oct 04 07:32:41 EDT 2011
Strange, which version are you running on? We are on v8.3.

Regards,

Peter

I'm using DOORS 9.3.0.2 so odd it isn't working